package com.walkline.notes.dao;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.notes.NotesException;
import com.walkline.notes.NotesSDK;
import com.walkline.notes.inf.Note;
import com.walkline.notes.inf.Notes;
import com.walkline.util.Function;

public class NotesNotes extends NotesObject implements Notes
{
	private int _count = 0;
	private Note[] _notes;

	public NotesNotes(NotesSDK notes, JSONObject jsonObject) throws NotesException
	{
		super(notes, jsonObject);

		try {
			_count = jsonObject.getInt("count");
		} catch (JSONException e1) {}

		JSONArray jsonArray = jsonObject.optJSONArray("notes");

		if (jsonArray != null && jsonArray.length() > 0)
		{
			_notes = new Note[jsonArray.length()];

			for (int i=0; i<jsonObject.length(); i++)
			{
				try {
					_notes[i] = (Note) jsonArray.get(i);
				} catch (JSONException e) {Function.errorDialog(e.toString());}
			}
		}
	}

	public Note[] getNotes() {return _notes;}

	public int getCount() {return _count;}
}